package thread_pool;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/5/23
 * Time:17:11
 * 内存溢出
 **/
public class PoolDemo34 {

    static ThreadLocal<MyBigClass> threadLocal = new ThreadLocal<>();

    static class MyBigClass{
        //声明1M的内存
        private byte[] bytes = new byte[1*1024*1024];
    }

    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                10,10,0, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(100)
        );
        for (int i = 0; i < 5; i++) {
            int finalI = i;
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName()+"编号："+finalI+"执行了存储方法");
                    MyBigClass myBigClass = new MyBigClass();
                    threadLocal.set(myBigClass);
                    myBigClass = null;
                }
            });
        }
    }
}
